packtype.hpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· HPP 代码 · 共 1,349 行 · 第 1/3 页

HPP
1,349
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


//
// Definition of type classes and other supporting classes for cv4 type
// packing.
//

//
// Please note that the leaf structures are defined prior to
// this program for other CV applications, this structure are reused such
// that every leaf class contains its corresponding pre-defined structure.
//

#ifndef _PACKTYPE_H_INCLUDED
#define _PACKTYPE_H_INCLUDED

#include <wclist.h>

#ifndef _CV4W_H_INCLUDED
#define _CV4W_H_INCLUDED
#include "cv4w.h"
#endif

typedef unsigned_16 leaf_index;

static const leaf_index NO_LEAF = 0;

//
// To indicate the optional vtab_offset field in LF_MLIST does not exists.
//
static const NO_VTAB_OFFSET     = -1;

//
// To indicate that no derivation information are available for a
// class/sttructure type record.
//
static const NO_DER_INFO        = 0x0000;

static const NO_TYPING_INFO     = 0;

class TypeArray;

class LFLeafStruct {

    public :

        LFLeafStruct( const leaf_index  leaf,
                      const char*       rawBuffer=0,
                      const uint        variantSize=0 );

        virtual ~LFLeafStruct() { }

        virtual void FixTypeIndex() { }

        // for the sake of putting lfleafstruct in wclist.
        bool operator==( const LFLeafStruct& ) const;

        bool IsEquivalent ( const LFLeafStruct& target ) const;

        void Put( ExeMaker& ) const;

        leaf_index Index() const {
            return _leaf;
        }

        VariantString& Variant() {
            return _variantString;
        }

        static LFLeafStruct* Error( const char*, const uint );

        static void SetLocalTypeArray( TypeArray& );
        static void SetGlobalTypeArray( TypeArray& t );

    protected :

        virtual bool IsEqual( const LFLeafStruct& ) const {
            return TRUE;
        }

        virtual void DerivedPut( ExeMaker& ) const { }

        static bool TypeEqual( const type_index, const type_index );
        static bool TypeListEqual( const type_index*,
                                   const type_index*,
                                   const uint );

        static bool AttrEqual( const cv_attrib, const cv_attrib );
        static bool AttrEqual( const cv_ptrattr, const cv_ptrattr );
        static bool AttrEqual( const cv_sprop, const cv_sprop );
        static bool AttrEqual( const cv_fldattr, const cv_fldattr );

        static void FixTypeList( type_index*, const uint );

    private :

        const leaf_index        _leaf;
        VariantString           _variantString;

        static TypeArray*       _localTypeArray;
        static TypeArray*       _globalTypeArray;
};

class LFSubField : public LFLeafStruct {

    public :

        LFSubField( const leaf_index  leaf,
                    const uint        recLen,
                    const char*       var = NULL,
                    const uint        varLen = 0 );

        virtual ~LFSubField() { }

        virtual void FixTypeIndex() { }

        // for the sake of putting lfsubfield in wclist.
        bool operator == ( const LFSubField& ) const;

        uint RecordLength() const {
            return _recordLength;
        }

        static LFSubField* Error( const char* );

    protected :

        bool IsEqual( const LFLeafStruct& ) const;

        virtual bool IsSubFieldEqual( const LFSubField& ) const {
            return TRUE;
        }

        virtual void DerivedPut( ExeMaker& ) const { }

        static unsigned_8 PadLen( const char* ptr );

    private :

        const LFSubField& dc( const LFLeafStruct& t ) const {
            return ( const LFSubField& ) t;
        }

        //
        // Record the length of a sub field record.  This is required
        // because for sub fields inside a field list, there is no record
        // length info append to the record.  The address of the next
        // sub field is calculate by adding the length of the current
        // record to the beginning address of the current record.
        //
        uint  _recordLength;
};

class LFNotTrans : public LFLeafStruct {

    public :

        LFNotTrans() : LFLeafStruct(LF_NOTTRANS) { }
        virtual ~LFNotTrans() { }

        static LFLeafStruct* Construct( const char*, const uint );

    protected :

        void DerivedPut( ExeMaker& ) const;
};

class LFNull : public LFLeafStruct {

    public :

        LFNull() : LFLeafStruct(LF_NULL) { }
        virtual ~LFNull() { }

        static LFLeafStruct* Construct( const char*, const uint );

    protected :

        void DerivedPut( ExeMaker& ) const;
};

class LFModifier : public LFLeafStruct {

    public :

        LFModifier( const lf_modifier& modifier,
                    const char*        var,
                    const uint         varLen )
                : LFLeafStruct( modifier.common.code, var, varLen ),
                  _modifier( modifier.f ) { }

        virtual ~LFModifier() {}

        static LFLeafStruct* Construct( const char*, const uint );

        void FixTypeIndex();

        static LFLeafStruct* Construct( const char* );

    protected :

        virtual void DerivedPut( ExeMaker& ) const;

        bool IsEqual( const LFLeafStruct& ) const;

    private :

        const LFModifier& dc( const LFLeafStruct& t ) const {
            return ( const LFModifier& ) t;
        }

        ct_modifier     _modifier;
};

class LFPointer : public LFLeafStruct {

    public :

        LFPointer( const lf_pointer&  pointer,
                   const char*        var,
                   const uint         varLen,
                   const type_index   trailingType )
                : LFLeafStruct( pointer.common.code, var, varLen ),
                  _pointer( pointer.f ),
                  _trailingType( trailingType )  { }

        virtual ~LFPointer() { }

        static LFLeafStruct* Construct( const char*, const uint );

        void FixTypeIndex();

    protected :

        virtual void DerivedPut( ExeMaker& ) const;

        bool IsEqual( const LFLeafStruct& ) const;

    private :

        const LFPointer& dc( const LFLeafStruct& t ) const {
            return ( const LFPointer& ) t;
        }

        ct_pointer     _pointer;
        type_index     _trailingType;
};

class LFArray : public LFLeafStruct {

    public :

        LFArray( const lf_array&    array,
                 const char*        var,
                 const uint         varLen )
                : LFLeafStruct( array.common.code, var, varLen ),
                  _array( array.f ) { }

        virtual ~LFArray() {}

        static LFLeafStruct* Construct( const char*, const uint );

        void FixTypeIndex();

    protected :

        virtual void DerivedPut( ExeMaker& ) const;

        bool IsEqual( const LFLeafStruct& ) const;

    private :

        const LFArray& dc( const LFLeafStruct& t ) const {
            return ( const LFArray& ) t;
        }

        ct_array    _array;  // Main array record structure.
};

class LFClass : public LFLeafStruct {

    public :

        LFClass( const lf_class&    classStruct,
                 const char*        var,
                 const uint         varLen )
                : LFLeafStruct( classStruct.common.code, var, varLen ),
                  _class( classStruct.f ) { }

        virtual ~LFClass() {}

        static LFLeafStruct* Construct( const char*, const uint );

        void FixTypeIndex();

    protected :

        virtual void DerivedPut( ExeMaker& ) const;

        bool IsEqual( const LFLeafStruct& ) const;

    private :

        const LFClass& dc( const LFLeafStruct& t ) const {
            return ( const LFClass& ) t;
        }

        ct_class     _class;
};

typedef LFClass LFStructure;

class LFUnion : public LFLeafStruct {

    public :

        LFUnion( const lf_union&    unionStruct,
                 const char*        var,
                 const uint         varLen )
                : LFLeafStruct( unionStruct.common.code, var, varLen ),
                  _union( unionStruct.f ) { }

        virtual ~LFUnion() {}

        static LFLeafStruct* Construct( const char*, const uint );

        void FixTypeIndex();

    protected :

        virtual void DerivedPut( ExeMaker& ) const;

        bool IsEqual( const LFLeafStruct& ) const;

    private :

        const LFUnion& dc( const LFLeafStruct& t ) const {
            return ( const LFUnion& ) t;
        }

        ct_union     _union;
};

class LFEnum : public LFLeafStruct {

    public :

        LFEnum( const lf_enum&     enumStruct,
                const char*        var,
                const uint         varLen )
                : LFLeafStruct( enumStruct.common.code, var, varLen ),
                  _enum( enumStruct.f ) { }

        virtual ~LFEnum() {}

        static LFLeafStruct* Construct( const char*, const uint );

        void FixTypeIndex();

    protected :

        virtual void DerivedPut( ExeMaker& ) const;

        bool IsEqual( const LFLeafStruct& ) const;

    private :

        const LFEnum& dc( const LFLeafStruct& t ) const {
            return ( const LFEnum& ) t;
        }

        ct_enum     _enum;
};

class LFProcedure : public LFLeafStruct {

    public :

        LFProcedure( const lf_procedure& procedure,
                     const char*         var,
                     const uint          varLen )
                : LFLeafStruct( procedure.common.code, var, varLen ),
                  _procedure( procedure.f ) { }

        virtual ~LFProcedure() {}

        static LFLeafStruct* Construct( const char*, const uint );

        void FixTypeIndex();

    protected :

        virtual void DerivedPut( ExeMaker& ) const;

        bool IsEqual( const LFLeafStruct& ) const;

    private :

        const LFProcedure& dc( const LFLeafStruct& t ) const {
            return ( const LFProcedure& ) t;
        }

        ct_procedure     _procedure;
};

class LFMFunction : public LFLeafStruct {

    public :

        LFMFunction( const lf_mfunction& mFunction,
                     const char*         var,
                     const uint          varLen )
                : LFLeafStruct( mFunction.common.code, var, varLen ),
                  _mFunction( mFunction.f ) { }

        virtual ~LFMFunction() {}

        static LFLeafStruct* Construct( const char*, const uint );

        void FixTypeIndex();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?