packtype.cpp

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

CPP
1,370
字号
/****************************************************************************
*
*                            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!
*
****************************************************************************/


#include <string.h>

#include <wclistit.h>
#include "common.hpp"
#include "cverror.hpp"
#include "makeexe.hpp"
#include "packtype.hpp"
#include "typemap.hpp"
#include "typearay.hpp"

extern uint NumLeafLength( const char* );

extern TypeIndexMap TypeMap;

TypeArray*  LFLeafStruct::_localTypeArray;
TypeArray*  LFLeafStruct::_globalTypeArray;

PSF LFFieldList::_subFieldConstructorTable[] = {
    LFSubField::Error,
    LFBClass::Construct,
    LFVBClass::Construct,
    LFIVBClass::Construct,
    LFEnumerate::Construct,
    LFFriendFcn::Construct,
    LFIndex::Construct,
    LFMember::Construct1,
    LFStMember::Construct2,
    LFMethod::Construct,
    LFNestedType::Construct,
    LFVFuncTab::Construct,
    LFFriendCls::Construct,
    LFOneMethod::Construct,
    LFVFuncOff::Construct,
};

// unused function section :
bool LFLeafStruct::operator == ( const LFLeafStruct& ) const
{
    throw InternalError("LFLeafStruct == gets call");
}

bool LFSubField::operator == ( const LFSubField& ) const
{
    throw InternalError("LFSubField == gets call");
}

bool my_ct_mlist::operator == ( const my_ct_mlist& ) const
{
    throw InternalError("my_ct_mlist == gets call");
}
// end section.

LFLeafStruct::LFLeafStruct( const leaf_index  leaf,
                            const char*       rawBuffer,
                            const uint        variantSize )
        : _leaf(leaf),
          _variantString(rawBuffer,variantSize) { }

bool LFLeafStruct::IsEquivalent( const LFLeafStruct& LFRecord ) const
/*******************************************************************/
{
    return ( _leaf == LFRecord._leaf &&
             _variantString == LFRecord._variantString &&
             IsEqual(LFRecord) );
}

LFLeafStruct* LFLeafStruct::Error( const char*, const uint )
{
    throw InternalError("Invalid/Unsupported type index detected.");
}

void LFLeafStruct::SetLocalTypeArray( TypeArray& t ) {
    _localTypeArray = &t;
}

void LFLeafStruct::SetGlobalTypeArray( TypeArray& t ) {
    _globalTypeArray = &t;
}

void LFLeafStruct::Put( ExeMaker& eMaker ) const
{
    eMaker.DumpToExe(_leaf);
    DerivedPut(eMaker);
    eMaker.DumpToExe(_variantString);
}

bool LFLeafStruct::TypeEqual( const type_index refIndex,
                              const type_index targetIndex )
/**********************************************************/
{
    if ( refIndex < CV_FIRST_NONPRIM || targetIndex < CV_FIRST_NONPRIM ) {
        return ( refIndex == targetIndex );
    }
    if ( TypeMap.IsDone(targetIndex) ) {
        return ( refIndex == TypeMap.Lookup(targetIndex) );
    }
    return ( (*_globalTypeArray)[refIndex] -> IsEquivalent(*(*_localTypeArray)[targetIndex]));
}


bool LFLeafStruct::TypeListEqual( const type_index* refIndices,
                                  const type_index* tIndices,
                                  const uint        count ) {
    for ( uint i = 0; i < count; i++ ) {
        if ( ! TypeEqual(refIndices[i], tIndices[i] ) ) {
            return FALSE;
        }
    }
    return TRUE;
}

bool LFLeafStruct::AttrEqual( const cv_fldattr ref,
                              const cv_fldattr target )
/*****************************************************/
{
    return ( ref.f.access == target.f.access &&
             ref.f.mprop == target.f.mprop &&
             ref.f.pseudo == target.f.pseudo &&
             ref.f.noinherit == target.f.noinherit &&
             ref.f.noconstruct == target.f.noconstruct );
}

bool LFLeafStruct::AttrEqual( const cv_attrib ref,
                              const cv_attrib target )
/****************************************************/
{
    return ( ref.f.isconst == target.f.isconst &&
             ref.f.isvol == target.f.isvol &&
             ref.f.unalign == target.f.unalign );
}

bool LFLeafStruct::AttrEqual( const cv_ptrattr ref,
                              const cv_ptrattr target )
/*****************************************************/
{
    return ( ref.f.type == target.f.type &&
             ref.f.mode == target.f.mode &&
             ref.f.isflat32 == target.f.isflat32 &&
             ref.f.isvol == target.f.isvol &&
             ref.f.isconst == target.f.isconst &&
             ref.f.unaligned == target.f.unaligned );
}

bool LFLeafStruct::AttrEqual( const cv_sprop ref,
                              const cv_sprop target )
/***************************************************/
{
    return ( ref.f.packed == target.f.packed &&
             ref.f.ctor == target.f.ctor &&
             ref.f.overops == target.f.overops &&
             ref.f.isnested == target.f.isnested &&
             ref.f.cnested == target.f.cnested &&
             ref.f.opassign == target.f.opassign &&
             ref.f.opcast == target.f.opcast &&
             ref.f.fwdref == target.f.fwdref &&
             ref.f.scoped == target.f.scoped );
}

LFSubField::LFSubField( const leaf_index  leaf,
                        const uint        recLen,
                        const char*       var,
                        const uint        varLen )
        : LFLeafStruct( leaf, var, varLen ),
          _recordLength( recLen )
/************************************************/
{
}

bool LFModifier::IsEqual( const LFLeafStruct& target ) const
/**********************************************************/
{
    return ( AttrEqual(_modifier.attr, dc(target)._modifier.attr ) &&
             TypeEqual(_modifier.index, dc(target)._modifier.index) );
}

bool LFPointer::IsEqual( const LFLeafStruct& target ) const
/*********************************************************/
{
    return ( AttrEqual(_pointer.attr, dc(target)._pointer.attr) &&
             TypeEqual( _pointer.type, dc(target)._pointer.type ) &&
             TypeEqual( _trailingType, dc(target)._trailingType) );
}

bool LFArray::IsEqual( const LFLeafStruct& target ) const
/*******************************************************/
{
    return ( TypeEqual( _array.elemtype, dc(target)._array.elemtype) &&
             TypeEqual( _array.idxtype,dc(target)._array.idxtype) );
}

bool LFClass::IsEqual( const LFLeafStruct& target ) const
/*******************************************************/
{
    return ( _class.count == dc(target)._class.count &&
             AttrEqual( _class.property, dc(target)._class.property ) &&
             TypeEqual( _class.field, dc(target)._class.field ) &&
             TypeEqual( _class.vshape, dc(target)._class.vshape ) );
}

bool LFUnion::IsEqual( const LFLeafStruct& target ) const
/*******************************************************/
{
    return ( _union.count == dc(target)._union.count &&
             AttrEqual( _union.property, dc(target)._union.property ) &&
             TypeEqual( _union.field, dc(target)._union.field ) );
}

bool LFEnum::IsEqual( const LFLeafStruct& target ) const
/******************************************************/
{
    return ( _enum.count == dc(target)._enum.count &&
             AttrEqual( _enum.property, dc(target)._enum.property ) &&
             TypeEqual( _enum.type, dc(target)._enum.type) &&
             TypeEqual( _enum.fList, dc(target)._enum.fList ) );
}

bool LFProcedure::IsEqual( const LFLeafStruct& target ) const
/***********************************************************/
{
    return ( _procedure.call == dc(target)._procedure.call &&
             _procedure.parms == dc(target)._procedure.parms &&
             TypeEqual( _procedure.rvtype, dc(target)._procedure.rvtype ) &&
             TypeEqual( _procedure.arglist, dc(target)._procedure.arglist ) );
}

bool LFMFunction::IsEqual( const LFLeafStruct& target ) const
/***********************************************************/
{
    return ( _mFunction.call == dc(target)._mFunction.call &&
             _mFunction.parms == dc(target)._mFunction.parms &&
             _mFunction.thisadjust == dc(target)._mFunction.thisadjust &&
             TypeEqual( _mFunction.thisptr, dc(target)._mFunction.thisptr ) &&
             TypeEqual( _mFunction.rvtype, dc(target)._mFunction.rvtype ) &&
             TypeEqual( _mFunction.class_idx, dc(target)._mFunction.class_idx ) &&
             TypeEqual( _mFunction.arglist, dc(target)._mFunction.arglist ) );
}

bool LFVtShape::IsEqual( const LFLeafStruct& target ) const
/*********************************************************/
{
    return ( _vtShape.count == dc(target)._vtShape.count );
}

bool LFCobol0::IsEqual( const LFLeafStruct& target ) const
/********************************************************/
{
    return TypeEqual( _cobol0.parent, dc(target)._cobol0.parent );
}

bool LFBArray::IsEqual( const LFLeafStruct& target ) const
/********************************************************/
{
    return TypeEqual( _bArray.type, dc(target)._bArray.type );
}

bool LFLabel::IsEqual( const LFLeafStruct& target ) const
/*******************************************************/
{
    return ( _label.mode == dc(target)._label.mode );
}

bool LFDimArray::IsEqual( const LFLeafStruct& target ) const
/**********************************************************/
{
    return ( TypeEqual( _dimArray.diminfo, dc(target)._dimArray.diminfo ) &&
             TypeEqual( _dimArray.utype, dc(target)._dimArray.utype ) );
}

bool LFVftPath::IsEqual( const LFLeafStruct& target ) const
/*********************************************************/
{
    if ( _vftPath.count == dc(target)._vftPath.count ) {
        return TypeListEqual(_bases,dc(target)._bases,_vftPath.count);
    }
    return FALSE;
}

bool LFArgList::IsEqual( const LFLeafStruct& target ) const
/*********************************************************/
{
    if ( _argList.argcount == dc(target)._argList.argcount ) {
        return TypeListEqual(_indices,dc(target)._indices,_argList.argcount);
    }
    return FALSE;
}

bool LFDefArg::IsEqual( const LFLeafStruct& target ) const
/********************************************************/
{
    return TypeEqual( _defArg.index, dc(target)._defArg.index );
}

bool LFDerived::IsEqual( const LFLeafStruct& target ) const
/*********************************************************/
{
    if ( _derived.count == dc(target)._derived.count ) {
        return TypeListEqual(_indices, dc(target)._indices, _derived.count);
    }
    return FALSE;
}

bool LFBitField::IsEqual( const LFLeafStruct& target ) const
/**********************************************************/
{
    return ( _bitField.length == dc(target)._bitField.length &&
             _bitField.position == dc(target)._bitField.position  &&
             TypeEqual( _bitField.type, dc(target)._bitField.type) );
}

bool LFMethodList::IsEqual( const LFLeafStruct& target ) const
/************************************************************/
{
    if ( _mList -> entries() != dc(target)._mList -> entries() ) {
        return FALSE;
    }
    WCPtrConstSListIter<my_ct_mlist> refIter(*_mList);
    WCPtrConstSListIter<my_ct_mlist> tIter(*dc(target)._mList);
    my_ct_mlist* refPtr;
    my_ct_mlist* tPtr;

    while ( ++refIter && ++tIter ) {
        refPtr = refIter.current();
        tPtr = tIter.current();
        if ( refPtr -> vtab != tPtr-> vtab ||
             ! AttrEqual( refPtr -> attr, tPtr -> attr ) ||
             ! TypeEqual( refPtr -> type, tPtr -> type ) ) {
            return FALSE;
        }
    }
    return TRUE;
}

bool LFDimConu::IsEqual( const LFLeafStruct& target ) const
/*********************************************************/
{
    return ( _dimConu.rank == dc(target)._dimConu.rank &&
             TypeEqual(_dimConu.index, dc(target)._dimConu.index) );
}

bool LFDimConlu::IsEqual( const LFLeafStruct& target ) const
/**********************************************************/
{
    return ( _dimConlu.rank == dc(target)._dimConlu.rank &&
             TypeEqual(_dimConlu.index, dc(target)._dimConlu.index) );
}

// RefSym.

bool LFBClass::IsSubFieldEqual( const LFSubField& target ) const
/**************************************************************/
{
    return ( AttrEqual(_bClass.attr, dc(target)._bClass.attr) &&
             TypeEqual(_bClass.type, dc(target)._bClass.type) );
}

bool LFVBClass::IsSubFieldEqual( const LFSubField& target ) const
/***************************************************************/
{
    return ( AttrEqual(_vbClass.attr, dc(target)._vbClass.attr) &&
             TypeEqual(_vbClass.btype, dc(target)._vbClass.btype) &&
             TypeEqual(_vbClass.vtype, dc(target)._vbClass.vtype) );
}

bool LFEnumerate::IsSubFieldEqual( const LFSubField& target ) const
/*****************************************************************/
{
    return ( AttrEqual(_enumerate.attr, dc(target)._enumerate.attr) );
}

bool LFFriendFcn::IsSubFieldEqual( const LFSubField& target ) const
/*****************************************************************/
{
    return TypeEqual(_friendFcn.type, dc(target)._friendFcn.type);
}

bool LFIndex::IsSubFieldEqual( const LFSubField& target ) const
/*************************************************************/
{
    return ( TypeEqual(_index.index, dc(target)._index.index) );
}

bool LFMember::IsSubFieldEqual( const LFSubField& target ) const
/**************************************************************/
{
    return ( AttrEqual(_member.attr, dc(target)._member.attr) &&
             TypeEqual(_member.type, dc(target)._member.type) );
}

bool LFMethod::IsSubFieldEqual( const LFSubField& target ) const
/**************************************************************/
{
    return ( _method.count == dc(target)._method.count &&
             TypeEqual(_method.mList,dc(target)._method.mList) );
}

bool LFNestedType::IsSubFieldEqual( const LFSubField& target ) const
/******************************************************************/
{
    return TypeEqual(_nestedType.index, dc(target)._nestedType.index);
}

bool LFVFuncTab::IsSubFieldEqual( const LFSubField& target ) const
/****************************************************************/
{
    return TypeEqual(_vFuncTab.type, dc(target)._vFuncTab.type);
}

bool LFFriendCls::IsSubFieldEqual( const LFSubField& target ) const
/*****************************************************************/
{
    return TypeEqual(_friendCls.type, dc(target)._friendCls.type);
}

bool LFOneMethod::IsSubFieldEqual( const LFSubField& target ) const
/*****************************************************************/
{
    return ( AttrEqual(_oneMethod.attr, dc(target)._oneMethod.attr) &&
             TypeEqual(_oneMethod.type, dc(target)._oneMethod.type) );
}

bool LFVFuncOff::IsSubFieldEqual( const LFSubField& target ) const
/****************************************************************/
{
    return ( _vFuncOff.offset == dc(target)._vFuncOff.offset &&
             TypeEqual(_vFuncOff.type, dc(target)._vFuncOff.type) );

⌨️ 快捷键说明

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