s37dbtyp.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 668 行 · 第 1/2 页

C
668
字号
/****************************************************************************
*
*                            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 <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include "standard.h"
#include "coderep.h"
#include "cgdefs.h"
#include "sysmacro.h"
#include "offset.h"
#include "typedef.h"
#include "s37bead.h"
#include "s37dbg.h"

typedef int handle;
#include "s37dbtyp.def"

extern uint            Length(char*);
extern byte           *Copy(void*,void*,uint);
extern type_def       *TypeAddress(cg_type);
extern char           *DbgFmtInt( char *, offset );
extern char           *DbgFmtStr( char *, char *, id_len );
extern void            PutStream(handle ,byte *,uint );


extern    unsigned_16           TypeIdx;

static short int TTagCount;
static short int NTagCount;

static cdebug_type_any   *TypeHead;
static cdebug_type_any  **TypeNext;
static cdebug_type_name  *TNameHead;
static cdebug_type_name **TNameNext;

static char const Scopes[][7] = {
    "struct","union","enum"
};

enum {
    SCOPE_STRUCT = 1,
    SCOPE_UNION  = 2,
    SCOPE_ENUM   = 3,
    SCOPE_MAX    = 4
};

extern  dbg_type DBFtnType( char *nm, dbg_ftn_type tipe ){
/*********************************************************/
    nm = NULL;
    tipe = 0;
    return( 0 );
}

extern  dbg_type DBScalar( char *nm, cg_type tipe ){
/**************************************************/
    type_def           *tipe_addr;
    cdebug_type_scalar *new;
    dbg_type           tnum;

    tipe_addr = TypeAddress( tipe );
    _Alloc( new, sizeof( *new ) );
    if( tipe_addr->refno == T_DEFAULT ) { /* SCALAR_VOID */
        new->common.class = CDEBUG_TYPE_INTEGER;
        new->common.len = 4;
        new->sign = 0;
    }else{ /* int or float */
        new->common.len = tipe_addr->length;
        if( tipe_addr->attr & TYPE_FLOAT ) {
            new->common.class = CDEBUG_TYPE_FLOAT;
        } else {
            new->common.class = CDEBUG_TYPE_INTEGER;
            new->sign =  tipe_addr->attr & TYPE_SIGNED ? -1 : 0;
        }
    }
    tnum = AddType( new );
    if( *nm != '\0' ) {
        AddTName( nm, tnum );
    }
    return( tnum );
}

extern  dbg_type DBScope( char *nm ) {
/* mode scope name to a number other than DBG_NIL */
    dbg_type num;

    num = 0;
    while( num < 3 ){
        if( strcmp( Scopes[num], nm ) == 0 ){
            break;
        }
        ++num;
    }
    return( num+1 );
}

extern  name_entry      *DBBegName( char *nm, dbg_type scope ) {
/**************************************************************/

    name_entry  *name;
    id_entry    *id;
    uint        len;

    len = Length( nm );
    _Alloc( name, sizeof( *name )  );
    _Alloc( id, sizeof( *id )-1 +len );
    id->len = len;
    Copy( nm, id->name, len );
    name->id = id;
    name->scope = scope;
    name->refno = DBG_NIL_TYPE;
    return( name );
}

extern  dbg_type DBForward( name_entry *name ) {
/* assign a type number for undefined type***************/
    if( name->refno == DBG_NIL_TYPE ) {
        name->refno = ++TypeIdx;
    }
    return( name->refno );
}

extern  dbg_type  DBEndName( name_entry *name, dbg_type tipe ) {
/**************************************************************/
    cdebug_type_any *tptr;

    tptr = FindType( tipe );
    if( name->refno != DBG_NIL_TYPE ) { /* rename type to used name */
        tptr->common.refno = name->refno;
    }
    if( name->scope == DBG_NIL_TYPE  ) {
        AddTId( name->id, tptr->common.refno ); /*typedef ?*/
        _Free( name->id, sizeof( id_entry )-1 + name->id->len );
    }else if( name->scope == SCOPE_ENUM ){
        tptr->enums.id = name->id;
    }else{
        tptr->tags.id = name->id;
    }
    _Free( name, sizeof( *name ) );
    return( tptr->common.refno );
}

extern  dbg_type DBCharBlock( unsigned_32 len ){
/*******************************************************/
    len = 0;
    return( 0 );
}

extern  dbg_type DBIndCharBlock( bck_info *len, cg_type len_type, int off ){
/**************************************************************************/
    len = NULL;
    len_type = 0;
    off = 0;
    return( 0 );
}

extern  dbg_type  DBDereference( cg_type ptr_type, dbg_type base ) {
/******************************************************************/
    ptr_type = 0;
    base = 0;
    return( 0 );
}

extern  dbg_type  DBFtnArray( bck_info *bk, cg_type lo_bound,
                cg_type num_elts, int dim_off,dbg_type base ) {
/**************************************************************/
    bk = NULL;
    lo_bound = 0;
    num_elts = 0;
    dim_off = 0;
    base = 0;
    return( 0 );
}

extern  dbg_type  DBArray( dbg_type idx, dbg_type base ){
/*******************************************************/
    idx = base = 0;
    return( 0 );
}

extern  dbg_type DBIntArray( unsigned_32 hi, dbg_type base ) {
/********** Make cdebug array type **************************/
    cdebug_type_array *new;
    cdebug_type_any *bptr;

    new = _Alloc( new, sizeof( *new ) );
    new->common.class = CDEBUG_TYPE_ARRAY;
    new->base = base;
    bptr = FindType( base );
    new->common.len = (hi+1) * bptr->common.len;
    new->length = (hi+1);
    return( AddType( new ) );
}

extern  dbg_type DBSubRange( signed_32 lo, signed_32 hi, dbg_type base ){
/***********************************************************************/
    lo=hi=base=0;
    return( 0 );
}

extern  dbg_type DBPtr( cg_type ptr_tipe, dbg_type base ){
    cdebug_type_pointer *new;
    type_def           *tipe_addr;

    tipe_addr = TypeAddress( ptr_tipe );
    _Alloc( new, sizeof( *new ) );
    new->common.len = tipe_addr->length;
    new->common.class = CDEBUG_TYPE_POINTER;
    new->base = base;
    return( AddType( new ) );
}


extern  cdebug_type_tags *DBBegStruct( cg_type tipe, bool is_struct ) {
/**************************************/
    cdebug_type_tags   *new;

    new = _Alloc( new, sizeof( *new ) );
    new->common.class =  is_struct ? CDEBUG_TYPE_STRUCT
                                   : CDEBUG_TYPE_UNION;
    new->common.len = TypeAddress( tipe )->length;
    new->index = 0;
    new->list = NULL;
    new->id = NULL;
    return( new );
}

extern  void    DBAddField( cdebug_type_tags *st, unsigned_32 off,
                            char *nm, dbg_type  base ) {
/******************************************************/

    DBAddBitField( st, off, 0, 0, nm, base );
}

extern  void    DBAddBitField( cdebug_type_tags *st, unsigned_32 off,
                    byte b_strt, byte b_len, char *nm, dbg_type base ) {
/******************************************************************/

    cdebug_member_entry  *field;
    cdebug_member_entry  *curr;
    cdebug_member_entry **owner;
    uint                  len;

    len = Length( nm );
    _Alloc( field, sizeof( cdebug_member_entry ) - 1 + len );
    field->id.len = len;
    Copy( nm, field->id.name, len );
    if( b_len != 0 ){
        field->tref = MkBitType( b_strt, b_len );
    }else{
        field->tref = base;
    };
    field->off  = off;
    field->b_strt = b_strt;
    field->b_len  = b_len;
    owner = &st->list;
    for(;;) {
        curr = *owner;
        if( curr == NULL ) break;
        if( off < curr->off ) break;
        if( (off == curr->off) && (b_strt <= curr->b_strt) ) break;
        owner = &curr->next;
    }
    field->next = curr;
    *owner = field;
    st->index++;
}

extern  dbg_type        DBEndStruct( cdebug_type_tags *st ) {
/*******************************************************/
    return( AddType( st ) );
}

extern  cdebug_type_enums *DBBegEnum( cg_type  tipe ) {
/***************************************************/

    cdebug_type_enums   *new;

    _Alloc( new, sizeof( *new ) );
    new->common.class = CDEBUG_TYPE_ENUMS;
    new->common.len = TypeAddress( tipe )->length;
    new->index = 0;
    new->list = NULL;
    new->tref = DBScalar( "", tipe );
    new->id = NULL;
    return( new );
}

extern  void DBAddConst( cdebug_type_enums *en, char *nm, signed_32  val ) {
/*********************************************************************/

    cdebug_enum  *cons;
    cdebug_enum  *curr;
    cdebug_enum **owner;
    uint          len;

    len = Length( nm );
    _Alloc( cons, sizeof( *cons ) - 1 + len );
    cons->id.len = len;
    Copy( nm, cons->id.name, len );
    cons->val = val;
    owner = &en->list;
    for(;;) {
        curr = *owner;

⌨️ 快捷键说明

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