⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defarg.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            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 "plusplus.h"
#include "cgfront.h"
#include "name.h"
#include "errdefns.h"
#include "initdefs.h"
#include "fnbody.h"
#include "stats.h"
#include "defarg.h"
#include "ring.h"
#include "codegen.h"
#include "pcheader.h"
#include "carve.h"

static CNV_DIAG diagDefarg =        // diagnosis for def. argument conversion
    {   ERR_DEFARG_IMPOSSIBLE
    ,   ERR_DEFARG_AMBIGUOUS
    ,   ERR_CALL_WATCOM
    ,   ERR_DEFARG_PRIVATE
    ,   ERR_DEFARG_PROTECTED
    };

ExtraRptCtr( ctr_defargs );
ExtraRptCtr( ctr_defargs_intconst );
ExtraRptCtr( ctr_defargs_fpconst );
ExtraRptCtr( ctr_defargs_symbol );
ExtraRptCtr( ctr_defargs_complex );

#define BLOCK_RELOC_LIST        16
static carve_t carveRELOC_LIST;

#ifndef NDEBUG

// for debugging, keep list of defarg ptree so we can free them in our
// fini routine
static PTREE DefargList = NULL;

void DefArgPCHWrite( void )
/*************************/
{
    PTREE defarg_list;

    defarg_list = PTreeGetIndex( DefargList );
    PCHWrite( &defarg_list, sizeof( defarg_list ) );
}

void DefArgPCHRead( void )
/************************/
{
    DefargList = PTreeMapIndex( PCHReadPtr() );
}

static void defargFreePtrees( void )  // FREE ALL DEFARG PTREES
{
    PTREE curr;
    PTREE next;
    PTREE defarg_info;

    next = NULL;
    for( curr = DefargList; curr != NULL; curr = next ) {
        next = curr->u.subtree[1];
        defarg_info = curr->u.subtree[0];
        NodeFreeDupedExpr( defarg_info->u.type.next );
        PTreeFree( defarg_info );
        PTreeFree( curr );
    }
    DefargList = NULL;
}

PTREE storeIfDebug(PTREE defarg_info)
{
    PTREE link_node;

    // for debugging, keep list of defarg ptree
    // so we can free them in our fini routine
    link_node = PTreeAlloc();
    link_node->op = PT_BINARY;
    // store defarg info at subtree zero
    link_node->u.subtree[0] = defarg_info;
    // link to rest of list
    link_node->u.subtree[1] = DefargList;
    DefargList = link_node;
    return link_node;
}

PTREE retrieveIfDebug(PTREE defarg_info)
{
    return defarg_info == NULL ? NULL : defarg_info->u.subtree[0];
}
#else

#define storeIfDebug(defarg_info) defarg_info
#define retrieveIfDebug(defarg_info) defarg_info

#endif

static PTREE copyRtn (  // Copy Routine -- pass to PTreeCopyPrefix
/******************/
    PTREE curr,         // - addr( current node )
    void *param )       // - param
{

    PTREE copy;
    RELOC_LIST *reloc_list;
    PTO_FLAG flags;
    PTREE partner;
    PTREE partner_copy;

    reloc_list = (RELOC_LIST *)param;

    copy = NULL;
    switch( curr->op ) { // allocate and copy ourselves for special cases
    case PT_FLOATING_CONSTANT :
    case PT_DUP_EXPR :
    case PT_SYMBOL :
        copy = PTreeAlloc();
        *copy = *curr;
        copy->decor = PtdDuplicateReloc( curr, reloc_list );
        break;
    }

    switch( curr->op ) {
    case PT_FLOATING_CONSTANT :
        copy->u.floating_constant = BFCopy( curr->u.floating_constant );
        break;
    case PT_DUP_EXPR :
        if( curr->flags & PTF_DUP_VISITED ) {
            // have already copied partner
            curr->flags &= ~PTF_DUP_VISITED;
            partner = curr->u.dup.node;
            DbgAssert( partner != NULL );
            partner_copy = partner->u.dup.node;
            DbgAssert( partner_copy != NULL );
            DbgAssert( partner_copy->u.dup.node == curr );
            copy->u.dup.subtree[0] = partner_copy->u.dup.subtree[0];
            partner_copy->u.dup.node = copy;
            copy->u.dup.node = partner_copy;
            partner->u.dup.node = curr;
        } else {
            partner = curr->u.dup.node;
            partner->flags |= PTF_DUP_VISITED;
            curr->u.dup.node = copy;
        }
        break;
    case PT_SYMBOL :
        // relocate symbol
        copy->u.symcg.symbol = SymReloc( curr->u.symcg.symbol, reloc_list );
        copy->u.symcg.result = NULL;
        break;
    default :
        copy = PTreeAssignReloc( NULL, curr, reloc_list );
        flags = PTreeOpFlags(curr);
        if( flags & PTO_BINARY ) {
            copy->u.subtree[0] = NULL;
            copy->u.subtree[1] = NULL;
        }
        if( flags & PTO_UNARY ) {
            copy->u.subtree[0] = NULL;
        }
        break;
    }
    copy->flags |= PTF_DEFARG_COPY; // mark this ptree as a copy for defargs
    return copy;
}

static PTREE defaultArgSymError( int msg, PTREE expr, SYMBOL sym )
{
    PTreeSetErrLoc( expr );
    if( sym != NULL ) {
        CErr2p( msg, sym );
        sym->flag |= SF_ERROR;
    } else {
        CErr1( msg );
    }
    expr = PTreeErrorNode( expr );
    return( expr );
}


static PTREE symCheck( PTREE expr )
{
    SYMBOL sym;
    SCOPE scope;

    if( expr->op != PT_SYMBOL ) {
        return( expr );
    }
    sym = expr->u.symcg.symbol;
    if( sym == NULL ) {
        expr = defaultArgSymError( ERR_DEFAULT_ARG_USES_THIS, expr, sym );
    } else {
        if( ! SymIsTemporary( sym ) ) {
            scope = SymScope( sym );
            if( ScopeType( scope, SCOPE_FUNCTION ) ) {
                expr = defaultArgSymError( ERR_DEFAULT_ARG_USES_ARG, expr, sym );
            } else if( ScopeType( scope, SCOPE_BLOCK ) ) {
                expr = defaultArgSymError( ERR_DEFAULT_ARG_USES_LOCAL,expr,sym);
            }

⌨️ 快捷键说明

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